<html>
<head>
<title> System Management & Security </title>
<link rel="stylesheet" type="text/css" href="css/html.css">
<link rel="stylesheet" type="text/css" href="css/docbook.css">
<link rel="stylesheet" type="text/css" href="css/syntax.css">
</head>

<body>

<div class="CODELISTING">
<pre>
	<span class="lnr"> 1 </span><span class="PreProc">#include </span><span class="Constant">&lt;signal.h&gt;</span>
	<span class="lnr"> 2 </span><span class="PreProc">#include </span><span class="Constant">&lt;unistd.h&gt;</span>
	<span class="lnr"> 3 </span><span class="PreProc">#include </span><span class="Constant">&lt;stdio.h&gt;</span>
	<span class="lnr"> 4 </span><span class="PreProc">#include </span><span class="Constant">&lt;errno.h&gt;</span>
	<span class="lnr"> 5 </span>
	<span class="lnr"> 6 </span><span class="Type">int</span> signo = <span class="Constant">0</span>;
	<span class="lnr"> 7 </span>
	<span class="lnr"> 8 </span><span class="Type">void</span> handler(<span class="Type">int</span> signal)
	<span class="lnr"> 9 </span>{
	<span class="lnr">10 </span>        signo = signal;
	<span class="lnr">11 </span>}
	<span class="lnr">12 </span>
	<span class="lnr">13 </span><span class="Type">int</span> main(<span class="Type">int</span> argc, <span class="Type">char</span> **argv)
	<span class="lnr">14 </span>{
	<span class="lnr">15 </span>        sigset_t signalMask;
	<span class="lnr">16 </span>        <span class="Statement">if</span>(sigfillset(&amp;signalMask) == -<span class="Constant">1</span>)
	<span class="lnr">17 </span>        {
	<span class="lnr">18 </span>                perror(<span class="Constant">&quot;sigfillset&quot;</span>);
	<span class="lnr">19 </span>                <span class="Statement">return</span> -<span class="Constant">1</span>;
	<span class="lnr">20 </span>        }
	<span class="lnr">21 </span>
	<span class="lnr">22 </span>        <span class="Type">struct</span> sigaction action;
	<span class="lnr">23 </span>        action.sa_handler = handler;
	<span class="lnr">24 </span>        action.sa_mask    = signalMask;
	<span class="lnr">25 </span>        action.sa_flags   =  SA_RESTART;
	<span class="lnr">26 </span>
	<span class="lnr">27 </span>        <span class="Statement">if</span>(sigaction(<span class="Constant">SIGINT</span>, &amp;action, <span class="Constant">NULL</span>) == -<span class="Constant">1</span>)
	<span class="lnr">28 </span>        {
	<span class="lnr">29 </span>                perror(<span class="Constant">&quot;sigaction&quot;</span>);
	<span class="lnr">30 </span>                <span class="Statement">return</span> -<span class="Constant">1</span>;
	<span class="lnr">31 </span>        }
	<span class="lnr">32 </span>
	<span class="lnr">33 </span>        printf(<span class="Constant">&quot;Now I go sleeping!</span><span class="Special">n</span><span class="Constant">&quot;</span>);
	<span class="lnr">34 </span>
	<span class="lnr">35 </span>        <span class="Statement">while</span>(sleep(<span class="Constant">60</span>));
	<span class="lnr">36 </span>
	<span class="lnr">37 </span>        <span class="Statement">return</span> signo;
	<span class="lnr">38 </span>}
</pre>
</div>

</body>
</html>
